var express = require('express')
var router = express.Router()
const { getAll, getOne, exec } = require('../db/index')

router.get('/', async (req, res) => {
  let sql = `select t2.sum as value,t1.type as name
              from 
	            blog_category t1,(SELECT category_id,COUNT(category_id) sum FROM blog_articles GROUP BY category_id) t2
              where
	            t1.id=t2.category_id `
  const data = await getAll(sql)
  res.send({
    code: 0,
    message: '查询成功',
    result: data,
  })
})

// 获取每个月份下的文章产量
router.get('/output', async function (req, res) {
  let sql = `SELECT MONTH(uploadTime) as month,count(*) as count from blog_articles GROUP BY MONTH(uploadTime)`
  const data = await getAll(sql)
  res.send({
    code: 0,
    message: '查询成功',
    result: data,
  })
})

module.exports = router
